package org.luxor.generator.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.luxor.generator.entity.DataSourceEntity;
import org.luxor.generator.service.SysDataSourceService;
import org.luxor.generator.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 自定义配置
 *
 * @author Mark sunlightcs@gmail.com
 */
@Api(tags = "配置数据库")
@RestController
@RequestMapping("/sys/dataSource")
public class SysDataSourceController {

    @Resource
    private SysDataSourceService sysDataSourceService;

    @ApiOperation("连接测试")
    @PostMapping("/ping")
    public R ping(@RequestBody DataSourceEntity dataSource) {
        return R.ok("测试成功").put("data", sysDataSourceService.save(dataSource));
    }

    @ApiOperation("查看")
    @GetMapping("/info")
    public R getDataSource() {
        return R.ok("获取成功").put("data", sysDataSourceService.info());
    }

    @ApiOperation("重置")
    @PostMapping("/reset")
    public R resetDataSource() {
        return R.ok("重置成功").put("data", sysDataSourceService.reset());
    }

}
